using System;
using System.Collections.Generic;
using dbvc.data;
using dbvc.Queries;

namespace dbvc.context.Script
{
    internal static partial class ScriptRole
    {
        public static void Save(this db_script self)
        {
            self.datestamp = DateTime.Now;
            GenericQuery<db_script>.Create(self,(o,i)=>o.id=i);
        }

        //public static IEnumerable<db_version_script> For(this db_script self, IList<db_version> vers)
        //{
        //    foreach (var v in vers)
        //    {
        //        yield return new db_version_script(){} 
        //    }
        //}

        //public static void Save(this IEnumerable<db_version_script> vers)
        //{
        //    foreach (var v in vers)
        //    {
        //        v.Save();
        //    }
        //}

        //public static void Save(this db_version_script ver)
        //{
        //    GenericQuery<db_version_script>.Create(ver);
        //}
    }

    public static class ActivityRole
    {
        public static void Save(this db_activity self)
        {
            GenericQuery<db_activity>.Create(self);
        }
    }

    public class CreateScript
    {
        private readonly db_activity Activity;
        private readonly db_script Script;
        private readonly db_user principal;

        public CreateScript(db_user _principal, db_script _scr)
        {
            principal = _principal;
            Script = _scr;
            Activity = new db_activity {action = "add script", datestamp = DateTime.Now, userstamp = principal.name};
        }

        public db_script Execute()
        {
            Script.userstamp = principal.name;
            Script.Save();
            Activity.Save();           
            
            return Script;
        }
    }
}